package com.tipfy.tmx;


class TiledTile
{
    /**
     * required, nonNegativeInteger
     */
    public var id:Int;

    /**
     *
     */
    public var properties:TiledProperties;

    /**
     *
     */
    public var image:TiledImage;

    /**
     * Constructor.
     */
    public function new(xml:Xml)
    {
        // Attributes.
        this.id = TiledAttributes.getNonNegativeInt(xml, "id");

        // Child elements.
        for (elem in xml.elements())
        {
            switch (elem.nodeName)
            {
                case "properties":
                    this._loadProperties(elem);
                case "image":
                    this._loadImage(elem);
                default:
                    throw "Invalid element <" + elem.nodeName + "> in <tile>";
            }
        }
    }


    /**
     * <properties>. minOccurs="0", maxOccurs="1"
     */
    private function _loadProperties(xml:Xml):Void
    {
        if (this.properties != null)
        {
            throw "Duplicated <properties> tag.";
        }

        this.properties = new TiledProperties(xml);
    }

    /**
     * <image>. minOccurs="0", maxOccurs="1"
     */
    private function _loadImage(xml:Xml):Void
    {
        if (this.image != null)
        {
            throw "Duplicated <image> tag.";
        }

        this.image = new TiledImage(xml);
    }
}
